/**
 * 
 */
package com.android.hw.projectmenu;

import com.android.hw.projectmenu.R;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.app.Dialog;
import android.content.DialogInterface.OnCancelListener;
import android.os.Bundle;
import android.util.Log;
import android.widget.CheckBox;
import android.widget.CompoundButton;
import android.os.SystemProperties;
/**
 * @author gaoshengpan
 *
 */
public class Logswitch extends Activity {
    private CheckBox chargeBox;
    private String TAG = "Logswitch";

    /**
     * 
     */
    public Logswitch() {
        // TODO Auto-generated constructor stub
    }
    
    /* (non-Javadoc)
     * @see android.app.Activity#onCreate(android.os.Bundle)
     */
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.log_switch);
        /*gaoshenpan 15-08-17 fix add alert message for chargeLog begin*/
        final AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle(R.string.alert)
        .setMessage(getString(R.string.alert_message))
        .setNegativeButton("Cancel",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //launch manage applications
                chargeBox.setChecked(false);
                dialog.cancel();
            }
        })
        .setPositiveButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
                //launch manage applications
                SystemProperties.set("persist.chargelog", "1");
                dialog.cancel();
            }
        });
        /*gaoshenpan 15-08-17 fix add alert message for chargeLog end*/
        chargeBox = (CheckBox)findViewById(R.id.charge_log);
        chargeBox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
            
            @Override
            public void onCheckedChanged(CompoundButton arg0, boolean arg1) {
                // TODO Auto-generated method stub
            	/*gaoshenpan 15-08-17 fix add alert message for chargeLog begin*/
                int idx = Integer.valueOf(SystemProperties
                        .get("persist.chargelog", "0"));
                if(arg1){
                    if(idx==1){
                        SystemProperties.set("persist.chargelog", "1");
                    }else{
                        builder.show();
                    }
                /*gaoshenpan 15-08-17 fix add alert message for chargeLog end*/
                }else{
                    SystemProperties.set("persist.chargelog", "0");
                }
            }
        });
        
    }
    
    /* (non-Javadoc)
     * @see android.app.Activity#onResume()
     */
    @Override
    protected void onResume() {
        // TODO Auto-generated method stub
        super.onResume();
        /*HY0066984 gaoshenpan 15-08-05 begin*/
        int idx = Integer.valueOf(SystemProperties
                .get("persist.chargelog", "0"));
        if (idx == 0) {
            chargeBox.setChecked(false);
            Log.d(TAG, "persist.chargelog=" + 0);
        } else {
            chargeBox.setChecked(true);
            Log.d(TAG, "persist.chargelog=" + 1);
        }
        /*HY0066984 gaoshenpan 15-08-05 end*/
    }

}
